<?php
namespace Common\Model;

class ConfModel {
    private $confFile = '/Conf/local.php';
    private $conf     = array();

    public function __construct() {
        $path           = realpath(dirname(__FILE__) . '/../../');
        $this->confFile = $path . $this->confFile;
        $this->conf     = $this->load($this->confFile);
    }

    /**
     * load
     * 载入配置文件
     *
     * @param mixed $file
     * @return void
     */
    public function load($file = null) {
        $file = empty($file) ? $this->confFile : $file;

        return include($file);
    }

    public function save2($d) {
        foreach($d as $k => $v) {
            $this->conf[$k] = $v;
        }

        $str = '<?php return ' . var_export($this->conf, true) . ';';
        $r   = file_put_contents($this->confFile, $str);

        return $r;
    }

}
